<?php

namespace App\Services;

/**
 * 所有服务层入口类继承 服务层验证输入数据安全
 *
 * Class Services
 * @package App\Services
 */
abstract class Services {

    /**
     * @var array 单例对象数组
     */
    public static $instance = [];

    # 一些接口约定
    #
    #


    /**
     * 服务类动态获取子模块
     *
     * @param $className
     * @param $args
     * @return mixed
     */
    public static function __callStatic($className = '', $args = [])
    {
        # 获取子类名
        $curClass = explode('\\', static::class);
        array_pop($curClass);
        $fullName = implode('\\', $curClass) . '\\' . ucfirst($className);
        # 获取对象
        if (class_exists($fullName)) {
            if (isset(self::$instance[$fullName]))
                return self::$instance[$fullName];

            return self::$instance[$fullName] = app()->make($fullName);
        }

    }

    /**
     * @return array
     */
    public static function getInstance($name = ''): array
    {
        if ($name) {
            return self::$instance[$name];
        }
        return self::$instance;
    }

}